package com.xlobo.api.fund.testcase;

import java.util.Map;

import org.junit.After;
import org.junit.AfterClass;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.experimental.categories.Category;

import com.xlobo.api.fund.parameter.FreezeBean;
import com.xlobo.api.fund.service.FreezeCall;
import com.ymt.core.tool.Logger;
import com.ymt.utils.annotation.TestCase;
import com.ymt.utils.annotation.TestSuite;
import com.ymt.utils.tag.P1;
import com.ymttest.business.service.XloboCallService;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;

/**
 * 根据UserId和AccountType，冻结指定账户金额 FreeMaker Template自动生成代码
 */
@TestSuite
public class Ts_FundFreeze {
	private static FreezeBean freezebean;
	private static FreezeCall freezecall;

	@BeforeClass
	public static void setUp() {
		Logger.createResultFile("根据UserId和AccountType，冻结指定账户金额");
	}

	@Before
	public void caseUp() {
		freezebean = new FreezeBean();
		freezecall = new FreezeCall();
	}

	@AfterClass
	public static void tearDown() {
		Logger.generateResult(freezecall.getOpurl());
	}

	@After
	public void caseDown() {
		Logger.end();
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_FundFreeze_001() {
		Logger.start(true,"根据UserId和AccountType，冻结指定账户金额成功");
		try {
			Map<?, ?> map = XloboCallService.Recharge(11.15);// 生成UserId
			String UserId = (String) map.get("UserId");// 用户Id
			Integer AccountType = (Integer) map.get("AmountType");
			double FreezeAmount = 5.55;// 冻结金额
			freezebean.setFreezeAmount(FreezeAmount);
			String FreezeTimeSpan = YMTDateUtil.getSysTime();// 冻结时间
			freezebean.setFreezeTimeSpan("00:00:00.1234567");
			freezebean.setUserId(UserId);
			freezebean.setUserAccountType(AccountType);
			// 业务编号
			String BusinessId = TestDataManager.getClientpaymentId();
			Logger.comment("业务编号:" + BusinessId);
			freezebean.setBusinessId(BusinessId);
			freezebean.setBusinessType(101);// 业务类型
			freezebean.setSystemSource(7);// 系统来源
			freezebean.setComment("自动化测试");// 备注
			// 请求编号
			String RequestId = TestDataManager.getRandomUUID() + "";
			Logger.comment("请求编号:" + RequestId);
			freezebean.setRequestId(RequestId);
			freezecall.setData(freezebean);
			freezecall.callService();
			Logger.debug(freezecall.getEntityString());
			Logger.debug(freezecall.getReturnData());
			// 验证
			Logger.comment("freezecall send:" + freezecall.getEntityString());
			Logger.comment("freezecall response:" + freezecall.getReturnData());
			Logger.verifyEquals("ok", freezecall.getStatus(), "验证冻结操作返回状态");
			Logger.verifyEquals("", freezecall.getMessage(), "验证冻结操作返回消息");
			// RequestId目前不返回，不验证
			// Logger.verifyEquals(RequestId, freezecall.getRequestId(),
			// "验证冻结操作返回请求ID");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_FundFreeze_002() {
		Logger.start(true,"UserId与AccountType不一致，冻结指定账户金额失败");
		try {
			Map<?, ?> map = XloboCallService.Recharge(11.15);
			String UserId = (String) map.get("UserId");// 用户Id
			// Integer AccountType = (Integer) map.get("AmountType");
			double FreezeAmount = 5.55;// 冻结金额
			freezebean.setFreezeAmount(FreezeAmount);
			// String FreezeTimeSpan = DateUtil.getSysTime();//冻结时间
			freezebean.setFreezeTimeSpan("00:00:00.1234567");
			freezebean.setUserId(UserId);
			freezebean.setUserAccountType(1);
			// 业务编号
			String BusinessId = TestDataManager.getClientpaymentId();
			Logger.comment("业务编号:" + BusinessId);
			freezebean.setBusinessId(BusinessId);
			freezebean.setBusinessType(101);// 业务类型
			freezebean.setSystemSource(7);// 系统来源
			freezebean.setComment("自动化测试");// 备注
			// 请求编号
			String RequestId = TestDataManager.getRandomUUID() + "";
			Logger.comment("请求编号:" + RequestId);
			freezebean.setRequestId(RequestId);
			freezecall.setData(freezebean);
			freezecall.callService();
			Logger.debug(freezecall.getEntityString());
			Logger.debug(freezecall.getReturnData());
			// 验证
			Logger.comment("freezecall send:" + freezecall.getEntityString());
			Logger.comment("freezecall response:" + freezecall.getReturnData());
			Logger.verifyEquals("未找到该用户的账户信息", freezecall.getMessage(), "验证错误消息");
			// RequestId目前不返回，不验证
			// Logger.verifyEquals(RequestId, freezecall.getRequestId(),
			// "验证冻结操作返回请求ID");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}

	@Test
	@Category(P1.class)
	@TestCase
	public void Tc_FundFreeze_003() {
		Logger.start(true,"根据UserId和AccountType不一致，冻结指定账户金额失败");
		try {
			Map<?, ?> map = XloboCallService.Recharge(11.15);
			String UserId = (String) map.get("UserId");// 用户Id
			// Integer AccountType = (Integer) map.get("AmountType");
			double FreezeAmount = 15.55;// 冻结金额
			freezebean.setFreezeAmount(FreezeAmount);
			// String FreezeTimeSpan = DateUtil.getSysTime();//冻结时间
			freezebean.setFreezeTimeSpan("00:00:00.1234567");
			freezebean.setUserId(UserId);
			freezebean.setUserAccountType(0);
			// 业务编号
			String BusinessId = TestDataManager.getClientpaymentId();
			Logger.comment("业务编号:" + BusinessId);
			freezebean.setBusinessId(BusinessId);
			freezebean.setBusinessType(101);// 业务类型
			freezebean.setSystemSource(7);// 系统来源
			freezebean.setComment("自动化测试");// 备注
			// 请求编号
			String RequestId = TestDataManager.getRandomUUID() + "";
			Logger.comment("请求编号:" + RequestId);
			freezebean.setRequestId(RequestId);
			freezecall.setData(freezebean);
			freezecall.callService();
			Logger.debug(freezecall.getEntityString());
			Logger.debug(freezecall.getReturnData());
			// 验证
			Logger.comment("freezecall send:" + freezecall.getEntityString());
			Logger.comment("freezecall response:" + freezecall.getReturnData());
			Logger.verifyEquals("未找到该用户的账户信息", freezecall.getMessage(), "验证错误消息");
			// RequestId目前不返回，不验证
			// Logger.verifyEquals(RequestId, freezecall.getRequestId(),
			// "验证冻结操作返回请求ID");
		} catch (Exception e) {
			Logger.fail(e);
		}
	}
}